package com.vehicle.mq.queue;

import com.alibaba.fastjson.JSON;
import com.vehicle.common.util.Jsons;
import com.vehicle.mq.message.BaseMessage;
import com.vehicle.mq.message.MailMessage;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Type;
import java.util.Objects;

/**
 * Created by yantingbin on 2017/12/4.
 */
public abstract class BaseMessageQueue<T extends BaseMessage> implements MessageQueue {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseMessage.class);

    public abstract void push(T t, EventQueue eq);

    public abstract T pop(EventQueue eq);

    public BaseMessage convert(String json) {
        BaseMessage bm = null;
        for (Type b : EventQueue.MESSAGE_BEANS) {
            bm = Jsons.fromJson(json, b);
            if (Objects.nonNull(bm)&&json.contains(Objects.toString(bm.getSerialVersionUID()))) {
                break;
            }
        }
        return bm;
    }
}
